//
//  YYFileManager.m
//  YYPaas
//
//  Created by 余意 on 2018/6/26.
//  Copyright © 2018年 余意. All rights reserved.
//

#import "YYFileManager.h"
#import "PlistFile.h"


//plist文件名称
static NSString * const localInfo = @"localInfo";

//用户登录信息在plist字典的对应Key值
static NSString * const userInfo = @"userInfo";

//用户本地设置信息在plist文件字典中对应的Key值
static NSString * const settingInfo = @"settingInfo";


@implementation YYFileManager

#pragma mark - 保存信息，实际上是存在LocalInfo.plist文件里面 infoKey为键名
+ (void)saveInfoToLocal:(id)info WithKey:(NSString *)infoKey
{
    NSMutableDictionary * userInfoDict = [PlistFile readDictionaryPlistForKey:NSDocumentDirectory WitFile:localInfo];
    if (!userInfoDict)
    {
        userInfoDict = [NSMutableDictionary new];
    }
    [userInfoDict setObject:info forKey:infoKey];
    [PlistFile updatePlist:NSDocumentDirectory WithFile:localInfo WithDictionary:userInfoDict];
}

#pragma mark - 根据key来查找localInfo.plist里面的数据
+ (id)infoFromLocalWithInfoKey:(NSString *)infoKey
{
    NSMutableDictionary * userInfoDic = [PlistFile readDictionaryPlistForKey:NSDocumentDirectory WitFile:localInfo];
    id info = [userInfoDic objectForKey:infoKey];
    return info;
}

#pragma mark - 保存用户信息
+ (void)saveUserInfoWithDictionary:(NSMutableDictionary *)dict
{
    [self saveInfoToLocal:dict WithKey:userInfo];
}

#pragma mark - 保存设置信息
+ (void)saveSettingInfoWithDictionary:(NSMutableDictionary *)dict
{
    [self saveInfoToLocal:dict WithKey:settingInfo];
}

#pragma mark - 查询用户信息
+ (NSMutableDictionary *)userInfo
{
    NSMutableDictionary * dict = (NSMutableDictionary *)[self infoFromLocalWithInfoKey:userInfo];
    return dict;
}

#pragma mark - 查询设置信息
+ (NSMutableDictionary *)settingInfo
{
    NSMutableDictionary * dict = (NSMutableDictionary *)[self infoFromLocalWithInfoKey:settingInfo];
    return dict;
}


@end
